package 网络.scokert;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class socketserver {
    public static void main(String[] args) throws IOException {
        int port = 22322;
        ServerSocket serverSocket = new ServerSocket(port);
        Socket socket = serverSocket.accept();//侦听此socket
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        StringBuilder sb = new StringBuilder();
        while ((len = inputStream.read(bytes)) != -1) {
            //注意指定编码格式，发送方和接收方一定要统一，建议使用UTF-8
            sb.append(new String(bytes, 0, len,"UTF-8"));
        }
        System.out.println(sb);
        inputStream.close();
        socket.close();
        serverSocket.close();
    }
}
